﻿#region Copyright

// /*
// SilverlightInEnterprise
// SilverlightInEnterprise.Common
// ScreenViewModelBase.cs
// 
// Author: Matt Van Horn
// Created 11/15/2011 8:28 PM
// Copyright: Silverlight in the Enterprise www.slinenterprise.com
// 
// Licensed under MS-PL http://www.opensource.org/licenses/MS-PL and while you 
// may use this in anyway you see fit and owe us nothing to do so, we wouldn't mind knowing that you got value out of the work we did (so we will do more) so 
// we ask that you leave a comment on www.slinenterprise.com or on the codeplex site slinenterprise.codeplex.com
// 
// */

#endregion

using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Windows.Input;
using SilverlightInEnterprise.Common.Events;
using SilverlightInEnterprise.Common.ViewModels;
using SilverlightInEnterprise.Interfaces.Screens;

namespace SilverlightInEnterprise.Common.Screens
{
    public class ScreenViewModelBase : ViewModelBase, IScreen
    {
        [Import(typeof (CloseScreenEvent), RequiredCreationPolicy = CreationPolicy.Shared)]
        internal CloseScreenEvent CloseEvent { get; set; }

        protected readonly string typeName;
        private readonly IScreenDefinition screenDefinition;

        protected ScreenViewModelBase(IScreenDefinition screenDefinition)
        {
            this.screenDefinition = screenDefinition;
        }

        protected ScreenViewModelBase(IScreenDefinition screenDefinition, Dictionary<string, object> arguments)
        {
            this.screenDefinition = screenDefinition;
            this.arguments = arguments;
        }

        public IScreenDefinition ScreenDefinition
        {
            get { return this.screenDefinition; }
        }

        public ICommand CloseCommand
        {
            get { return new GenericCommand(a => { }); }
        }

        public void Close(bool promptForSave)
        {
            throw new NotImplementedException();
        }

        protected void SendScreenClosed()
        {
            if (this.CloseEvent == null) throw new NullReferenceException("the close event is null");
            this.CloseEvent.Publish(this);
        }

        #region IsBlocked Property

        private bool _IsBlocked;

        public bool IsBlocked
        {
            get { return this._IsBlocked; }
            set
            {
                if (this._IsBlocked != value)
                {
                    this._IsBlocked = value;
                    this.OnPropertyChanged("IsBlocked");
                }
            }
        }

        #endregion

        private readonly Dictionary<string, object> arguments;

        public Dictionary<string, object> Arguments
        {
            get { return this.arguments; }
        }

        public string TypeName
        {
            get { return typeName; }
        }
    }
}